package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RequestMapping("/nursingLevel")
@RestController
@Api(tags = "护理等级")
public class NursingLevelController extends BaseController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping("/listAll")
    public ResponseResult<List<NursingLevelVo>> listAll() {
        List<NursingLevelVo> nursingLevelVos =nursingLevelService.listAll();
        return success(nursingLevelVos);
    }

    /**
     * 添加
     * @param nursingLevelDto
     * @return
     */
    @PostMapping("/insert")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.addNursingLevel(nursingLevelDto);
        return success();
    }

    /**
     * 分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/listByPage")
    public ResponseResult page(String name, Integer pageNum, Integer pageSize, Integer status){
        PageResponse pageResponse =nursingLevelService.page(name,pageNum,pageSize,status);
        return success(pageResponse);
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> searchById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo =nursingLevelService.searchById(id);
        log.info("查询结果：{}",nursingLevelVo);
        return success(nursingLevelVo);
    }

    /**
     * 根据id删除护理等级
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Long id){
        nursingLevelService.delete(id);
        return success();
    }

    /**
     * 更新护理等级
     * @param nursingLevelDto
     * @return
     */
    @PutMapping("/update")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    public ResponseResult openOrClose(@PathVariable Long id, @PathVariable Integer status){
        nursingLevelService.enableOrDisable(id,status);
        return success();
    }

}
